﻿$(function () {
    var f = app.city || 'shenzhen', a = app.ctx || '/' + f, b = app.biz || 'sale';
    ratesType = app.ratesType || 'ratestype';
    from = app.from;
    if (b == 'homepage') {
        b = app.cityModules[0];
    }
    var e = $('.popup-layer');
    var c = (function () {
        $('.search-layer').on('touchmove', function (n) {
            n.preventDefault();
        });
        $('#search-cancel').on('tap', function (n) {
            n.preventDefault();
            n.stopPropagation();
            $(this).closest('.search-layer').hide();
        });
        $('.search-body .text-body').on('input', function (n) {
            if ($.trim($(this).val()) == '') {
                $(this).next('.clear-text').hide();
            } else {
                $(this).next('.clear-text').show();
            }
        });
        $('.search-body .pop-clear-text').on('tap', function (n) {
            n.preventDefault();
            n.stopPropagation();
            $(this).prev('.text').val('');
            $(this).hide();
            location.href = $(this).attr('href');
        });
        var t = $('.search-list').slide({direction: 'vertical'});
        $('.search-layer .search-body .clear-text').on('tap', function (n) {
            n.preventDefault();
            n.stopPropagation();
            $(this).prev('.text').val('');
            $(this).hide();
            t.setPosition(0);
            if (s.get().length > 0) {
                z('_history_', s.get());
                A();
                $('.search-list').show();
            }
            $('.js-searchRecommendResult').html('');
            $('.search-recommend').hide();
        });
        $('.search-body .type').on('tap', function (n) {
            n.preventDefault();
            n.stopPropagation();
            if ($(this).next('.select').css('display') === 'none') {
                $(this).next('.select').show();
            } else {
                $(this).next('.select').hide();
            }
        });
        $(document).on('tap.searchType', function (n) {
            $('.search-body .select').hide();
        });
        $('.search-body .option').on('tap', function (H) {
            H.originalEvent.preventDefault();
            H.originalEvent.stopPropagation();
            b = $(this).attr('biz');
            if (b != 'sale') {
                $('.js-searchRecommendResult').html('');
                $('.search-recommend').hide();
            }
            var n = s.get();
            if (n.length === 0) {
                G();
            } else {
                A();
                z('_history_', n);
                $searchList.show();
            }
            $(this).closest('.search-body').find('.type .txt').text($(this).text());
            $('.js-search-input').val('').attr('placeholder', app.placeholders[b]);
            $('.search-body .select').hide();
        });
        var w = $('.search-layer'), h = $('.js-search-input'), k = $('.js-search-items'), l = $('.clear-text'),
            q = $('.clear-record');
        $searchList = $('.search-list');
        h.on('focus', function (H) {
            var n = $(this);
            if ($.trim(h.val()) == '') {
                l.hide();
                if (s.get().length > 0) {
                    z('_history_', s.get());
                    A();
                    $searchList.show();
                }
            } else {
                o(h.val());
                l.show();
                A();
                $searchList.show();
            }
        }).on('input', function (n) {
            A();
            $searchList.show();
            var H = $(this).val();
            if ((H = $.trim(H)) == '') {
                l.hide();
                z('_history_', s.get());
            } else {
                l.show();
                o(H);
            }
        }).on('keyup', function (H) {
            if (H.which == 13) {
                var n = $(this);
                var I = $.trim(n.val());
                if (I == '') {
                    return;
                }
                if (b == 'rates') {
                    return;
                }
                u($(this).val(), B($(this).val()));
            }
        }).on('blur', function (n) {
            l.hide();
            $('.search-list .items-body').show().data('number', 0).prefix({'transform': 'translate3d(0,0px,0)'});
        });
        $('.search-layer .cancel').tap(function (n) {
            n.stopPropagation();
            n.preventDefault();
            h.val('');
            h.blur();
            l.hide();
            if ($('#search-entry').val() != '') {
                $('.pop-clear-text').show();
            }
            k.html('');
            setTimeout(function () {
                w.hide();
            }, 50);
        });

        function m(n) {
            return b + '_' + n;
        }

        var g = (function () {
            var I = app.cityModules;
            var n = {
                sale: {
                    keywords: ['er', 'ers', 'ersh.ersho', 'ershou', 'ershouf', 'ershoufa', 'ershoufan', 'ershoufang', '二', '二手', '二手房'],
                    item: {name: '二手房', biz: 'sale', clazz: 'sale'}
                },
                rent: {
                    keywords: ['zu', 'zuf', 'zufa', 'zufan', 'zufang', '出', '出租', '出租房', '租', '租房'],
                    item: {name: '租房', biz: 'rent', clazz: 'rent'}
                },
                newhouse: {
                    keywords: ['xin', 'xinf', 'xinfa', 'xinfan', 'xinfang', '新', '新房'],
                    item: {name: '新房', biz: 'newhouse', clazz: 'newhouse'}
                },
                office: {
                    keywords: ['xie', 'xiez.xiezi', 'xiezil', 'xiezilo', 'xiezilou', 'xiezilouz', 'xiezilouzu', 'xiezilous', 'xieziloush', 'xiezulousho', 'xieziloushou', '写', '写字', '写字楼', '写字楼租', '写字楼售'],
                    item: {name: '写字楼', biz: 'office', clazz: 'office'}
                },
                school: {
                    keywords: ['xue', 'xueq', 'xuequ', 'xuequf', 'xuequfa', 'xuequfan', 'xuequfang', 'xuex', 'xuexi', 'xuexia', 'xuexiao', '学', '学校', '学区', '学区房'],
                    item: {name: '学区房', biz: 'school', clazz: 'scholar'}
                }
            };

            function H(L, J) {
                var K = [];
                if (L === 'sale' || L === 'rent' || L === 'newhouse' || L === 'officesale' || L === 'officerent' || L === 'school') {
                    var M = L.indexOf('office') > -1 ? 'office' : L;
                    Object.getOwnPropertyNames(n).forEach(function (P) {
                        if (M.indexOf(P) <= -1 && I.indexOf(P) > -1) {
                            var O = n[P].keywords;
                            for (var N = 0; N < O.length; N++) {
                                if (J == O[N]) {
                                    K.push(n[P].item);
                                    break;
                                }
                            }
                        }
                    });
                }
                return K;
            }

            return {
                get: function (K, J) {
                    return H(K, J);
                }
            };
        })();
        var r = {}, D, i;

        function o(n) {
            var I = $.Deferred();
            I.promise().done(function (J) {
                z(b, J);
            }).fail(function (J) {
                if (J) {
                    d(J);
                }
            });
            var H = m(n);
            if (r[H]) {
                I.resolve(r[H]);
            } else {
                if (D) {
                    clearTimeout(D);
                    preDefer && preDefer.reject();
                }
                preDefer = I;
                D = setTimeout(function () {
                    if (r[H]) {
                        I.resolve(r[H]);
                    } else {
                        var J = g.get(b, n);
                        var K = b.toUpperCase();
                        if (K == 'NEWHOUSEINDEX') {
                            K = 'NEWHOUSE';
                        }
                        /*$.post(a + '/search/getSearchKeyword', {
                            keyword: n,
                            type: K,
                            ratesType: ratesType
                        }).done(function (L) {
                            if (L) {
                                if (!$.isPlainObject(L)) {
                                    L = $.parseJSON(L);
                                }
                                r[H] = J.concat(L.data);
                                I.resolve(r[H]);
                            } else {
                                I.resolve(J);
                            }
                        }).fail(function () {
                            I.reject('系统异常，请稍候再试！');
                        });*/
                    }
                }, 250);
            }
        }

        var s = (function (N) {
            var P = N + '_search_history_';
            var L = 10;
            var H = '&i&';
            var K = '&v&';
            var n = lscache.supported();
            var O;
            if (n) {
                O = {
                    _keyStr: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
                    encode: function (V) {
                        var Y = '';
                        var S, Q, T, Z, R, X, W;
                        var U = 0;
                        V = O._utf8_encode(V);
                        while (U < V.length) {
                            S = V.charCodeAt(U++);
                            Q = V.charCodeAt(U++);
                            T = V.charCodeAt(U++);
                            Z = S >> 2;
                            R = (S & 3) << 4 | Q >> 4;
                            X = (Q & 15) << 2 | T >> 6;
                            W = T & 63;
                            if (isNaN(Q)) {
                                X = W = 64;
                            } else {
                                if (isNaN(T)) {
                                    W = 64;
                                }
                            }
                            Y = Y + this._keyStr.charAt(Z) + this._keyStr.charAt(R) + this._keyStr.charAt(X) + this._keyStr.charAt(W);
                        }
                        return Y;
                    },
                    decode: function (V) {
                        var Y = '';
                        var S, Q, T;
                        var Z, R, X, W;
                        var U = 0;
                        V = V.replace(/[^A-Za-z0-9+/=]/g, '');
                        while (U < V.length) {
                            Z = this._keyStr.indexOf(V.charAt(U++));
                            R = this._keyStr.indexOf(V.charAt(U++));
                            X = this._keyStr.indexOf(V.charAt(U++));
                            W = this._keyStr.indexOf(V.charAt(U++));
                            S = Z << 2 | R >> 4;
                            Q = (R & 15) << 4 | X >> 2;
                            T = (X & 3) << 6 | W;
                            Y = Y + String.fromCharCode(S);
                            if (X != 64) {
                                Y = Y + String.fromCharCode(Q);
                            }
                            if (W != 64) {
                                Y = Y + String.fromCharCode(T);
                            }
                        }
                        Y = O._utf8_decode(Y);
                        return Y;
                    },
                    _utf8_encode: function (S) {
                        S = S.replace(/rn/g, 'n');
                        var Q = '';
                        for (var T = 0; T < S.length; T++) {
                            var R = S.charCodeAt(T);
                            if (R < 128) {
                                Q += String.fromCharCode(R);
                            } else {
                                if (R > 127 && R < 2048) {
                                    Q += String.fromCharCode(R >> 6 | 192);
                                    Q += String.fromCharCode(R & 63 | 128);
                                } else {
                                    Q += String.fromCharCode(R >> 12 | 224);
                                    Q += String.fromCharCode(R >> 6 & 63 | 128);
                                    Q += String.fromCharCode(R & 63 | 128);
                                }
                            }
                        }
                        return Q;
                    },
                    _utf8_decode: function (S) {
                        var Q = '';
                        var T = 0;
                        var R = c1 = c2 = 0;
                        while (T < S.length) {
                            R = S.charCodeAt(T);
                            if (R < 128) {
                                Q += String.fromCharCode(R);
                                T++;
                            } else {
                                if (R > 191 && R < 224) {
                                    c2 = S.charCodeAt(T + 1);
                                    Q += String.fromCharCode((R & 31) << 6 | c2 & 63);
                                    T += 2;
                                } else {
                                    c2 = S.charCodeAt(T + 1);
                                    c3 = S.charCodeAt(T + 2);
                                    Q += String.fromCharCode((R & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
                                    T += 3;
                                }
                            }
                        }
                        return Q;
                    }
                };
            }

            function J() {
                var Q = b;
                if (Q == 'newhouseIndex') {
                    Q = 'newhouse';
                } else {
                    if (Q == 'transaction') {
                        Q = Q + app.bizType;
                    }
                }
                return P + Q;
            }

            function M(Q) {
                var R = {};
                return Q.filter(function (S) {
                    return R.hasOwnProperty(S) ? false : (R[S] = true);
                });
            }

            function I() {
                var Q = lscache.get(J());
                if (Q) {
                    return Q.split(H);
                }
                return [];
            }

            return {
                get: function () {
                    if (!n) {
                        return [];
                    }
                    var Q = I();
                    var R = [];
                    $.each(Q, function (S, U) {
                        var T = O.decode(U).split(K);
                        if (T.length == 3) {
                            R.push({name: T[0], value: T[1], type: T[2]});
                        } else {
                            if (T.length == 2) {
                                R.push({name: T[0], value: T[1]});
                            }
                        }
                    });
                    return R;
                }, add: function (S, U, T) {
                    if (n) {
                        var R = I();
                        if (T) {
                            R.unshift(O.encode(S + K + U + K + T));
                        } else {
                            R.unshift(O.encode(S + K + U));
                        }
                        R = M(R);
                        var Q = R.length;
                        if (Q > L) {
                            R = R.slice(0, L);
                        }
                        lscache.set(J(), R.join(H));
                    }
                }, remove: function () {
                    if (n) {
                        lscache.remove(J());
                    }
                }
            };
        })(f);
        var v = {
            handlers: {
                '_transfer_': function (I, H, n, J) {
                    I = '<a class="items" module="true" v="{biz}" href="javascript:;"><i class="icon iconfont icon-{clazz}"></i><span class="txt ellips">{name}</span><i class="icon-goto"></i></a>';
                    return I.replace('{biz}', J.biz).replace('{clazz}', J.clazz).replace('{name}', J.name);
                }
            }, register: function (I, H, n) {
                if (!H) {
                    throw'Type ' + I + ' template is not available';
                }
                v.handlers[I] = function (K, J, L) {
                    if (L) {
                        if (L.biz && L.clazz) {
                            return v.handlers['_transfer_'](H, K, J, L);
                        }
                        return n(H, K, J, L);
                    }
                    return '';
                };
            }, handle: function (H, n, I) {
                return v.handlers[H](H, n, I);
            }
        };
        var E = '<a class="items" href="javascript:;" s="{s}" sh="true" v="{v}"><i class="icon iconfont icon-yuyue"></i><span class="name ellips">{name}</span><span class="area ellips">{area}</span></a>';
        v.register('_history_', E, function (J, I, H, K) {
            var n = '';
            if (K.type) {
                n = K.type;
            }
            return J.replace('{v}', K.value).replace('{s}', K.value).replace('{area}', n).replace('{alias}', '').replace('{name}', K.name);
        });
        E = '<a class="items" href="javascript:;" s="{s}" v="{v}" t="{t}"><span class="name ellips">{name}</span><span class="area ellips">{alias}</span></a>';
        var p = function (K, J, H, L) {
            var n = '';
            var M = '';
            if (L.keywordType == 'COMMUNITY') {
                K = '<a class="items" href="javascript:;" s="{s}" v="{v}" t="{t}"></i><span class="name ellips">{name}</span><span class="area">社区</span></a>';
            } else {
                if (L.keywordType == 'AREA') {
                    K = '<a class="items" href="javascript:;" s="{s}" v="{v}" t="{t}" n="{n}"></i><span class="name ellips">{name}</span><span class="area">区域</span></a>';
                    if (L.parentAreaName) {
                        M = L.parentAreaName;
                    }
                } else {
                    if (L.keywordType == 'BUSINESS') {
                        K = '<a class="items" href="javascript:;" s="{s}" v="{v}" t="{t}" n="{n}"></i><span class="name ellips">{name}</span><span class="area">商圈</span></a>';
                        if (L.parentAreaName && L.childAreaName) {
                            M = L.parentAreaName + '-' + L.childAreaName;
                        }
                    }
                }
            }
            var I = L.alias;
            if (I != undefined && I !== '') {
                I = '(' + I + ')';
            } else {
                I = '';
            }
            if (L.keywordType == 'SCHOOL') {
                I = '(学校)';
            }
            return K.replace('{v}', L.id).replace('{s}', L.keyword).replace('{n}', M).replace('{t}', L.keywordType).replace('{alias}', I).replace('{area}', n).replace('{name}', L.keyword);
        };
        v.register('sale', E, p);
        v.register('rent', E, p);
        v.register('newhouse', E, p);
        v.register('newhouseIndex', E, p);
        v.register('garden', E, p);
        v.register('officesale', E, p);
        v.register('officerent', E, p);
        v.register('school', E, function (I, H, n, J) {
            return I.replace('{v}', J.id).replace('{name}', J.keyword).replace('{alias}', '').replace('{s}', J.keyword);
        });
        v.register('rates', E, function (J, I, n, K) {
            var L = '';
            if (K.type == 'AREA') {
                J = '<a class="items" href="javascript:;" s="{s}" v="{v}" t="{t}"></i><span class="name ellips">{name}</span><span class="area">区域</span></a>';
            } else {
                if (K.type == 'BUSINESS') {
                    J = '<a class="items" href="javascript:;" s="{s}" v="{v}" t="{t}"></i><span class="name ellips">{name}</span><span class="area">商圈</span></a>';
                } else {
                    if (K.type == 'STATION' || K.type == 'LINE') {
                        J = '<a class="items" href="javascript:;" s="{s}" v="{v}" t="{t}"></i><span class="name ellips">{name}</span><span class="area">{line}</span></a>';
                        if (K.parentArea) {
                            L = K.parentArea;
                        }
                    }
                }
            }
            var H = K.alias;
            if (H != undefined && H !== '') {
                H = '(' + H + ')';
            } else {
                H = '';
            }
            return J.replace('{name}', K.name).replace('{s}', K.name).replace('{v}', K.id).replace('{line}', L).replace('{alias}', H).replace('{t}', K.type);
        });
        v.register('transaction', E, function (J, I, n, K) {
            var H = '';
            if (K.type == 'AREA') {
                H = '区域';
            } else {
                if (K.type == 'BUSINESS') {
                    H = '商圈';
                } else {
                    if (K.type == 'GARDEN') {
                        if (K.alias != undefined && K.alias !== '') {
                            H = '(' + K.alias + ')';
                        }
                    }
                }
            }
            return J.replace('{name}', K.name).replace('{s}', K.name).replace('{v}', K.id).replace('{t}', K.type).replace('{alias}', H);
        });
        v.register('ask', E, function (I, H, n, J) {
            return I.replace('{name}', J.title).replace('{v}', J.id).replace('{alias}', '').replace('{s}', J.title);
        });
        v.register('ask-lista', E, function (I, H, n, J) {
            return I.replace('{name}', J.title).replace('{v}', J.id).replace('{alias}', '').replace('{s}', J.title);
        });
        v.register('ask-listb', E, function (I, H, n, J) {
            return I.replace('{name}', J.title).replace('{v}', J.id).replace('{alias}', '').replace('{s}', J.title);
        });
        v.register('ask-list', E, function (I, H, n, J) {
            return I.replace('{name}', J.title).replace('{v}', J.id).replace('{alias}', '').replace('{s}', J.title);
        });
        k.on('tap', 'a', function (L) {
            var K = $(this);
            var I = K.text();
            var H;
            var n = '';
            if (K.find('.area')) {
                n = K.find('.area').text();
            }
            if (K.attr('module')) {
                H = a + '/' + K.attr('v');
            } else {
                if (K.attr('sh')) {
                    H = K.attr('v');
                    I = K.find('.name').text();
                } else {
                    if (b == 'rates') {
                        I = K.attr('s');
                        if (K.attr('t') == 'LINE') {
                            H = a + '/metro/rates/l' + K.attr('v') + '?fs=S';
                        } else {
                            if (K.attr('t') == 'STATION') {
                                H = a + '/metro/rates/station/' + K.attr('v') + '?fs=S';
                            } else {
                                H = a + '/rates/' + K.attr('t').toLowerCase() + '/' + K.attr('v') + '?fs=S';
                            }
                        }
                    } else {
                        if (b.indexOf('transaction') != -1) {
                            var J = K.attr('s');
                            if (J != undefined && J !== '{s}') {
                                I = J;
                            }
                            H = app.base + '?keyword=' + I + '-' + K.attr('t').toLowerCase() + '-' + K.attr('v');
                        } else {
                            if (b === 'ask' || b === 'ask-lista' || b === 'ask-listb' || b === 'ask-list') {
                                H = a + '/ask/' + K.attr('v');
                            } else {
                                var J = K.attr('s');
                                if (J != undefined && J !== '{s}') {
                                    I = J;
                                }
                                H = B(I, K);
                            }
                        }
                    }
                }
            }
            u(I, H, n);
        });

        function u(H, n, I) {
            if (n) {
                s.add(H, n, I);
                setTimeout(function () {
                    location.href = n;
                }, 50);
            }
        }

        $('#search_from').bind('search', function () {
            var H = $('.js-search-input').val();
            if (H !== '') {
                if (b == 'rates' || b == 'transaction') {
                    return false;
                }
                var n = B(H);
                location.href = n;
            }
        });

        function B(H, n) {
            if (b == 'school') {
                if (from != undefined && from != '') {
                    return a + '/school?keyword=' + H + '&insource=index_search' + '&from=' + from;
                } else {
                    return a + '/school?keyword=' + H + '&insource=index_search';
                }
            } else {
                if (b == 'sale' || b == 'rent' || b == 'officerent' || b == 'officesale' || b == 'garden' || b == 'newhouse' || b == 'newhouseIndex') {
                    var K = '';
                    if (n && n.attr('n')) {
                        K = '/' + n.attr('n');
                    }
                    if (app.baseUrl != undefined && (b == 'sale' || b == 'rent')) {
                        var J = app.baseUrl + K + '?keyword=' + H + '&insource=index_search';
                        if (b == 'sale' && app.version) {
                            J += '&version=' + app.version;
                        }
                        return J;
                    }
                    var I = b;
                    if (b == 'newhouseIndex') {
                        I = 'newhouse';
                    } else {
                        if (b == 'officerent') {
                            I = 'office/rent';
                        } else {
                            if (b == 'officesale') {
                                I = 'office/sale';
                            }
                        }
                    }
                    var L = a + '/' + I + K + '?keyword=' + H + '&insource=index_search';
                    if (b == 'sale' && app.version) {
                        L += '&version=' + app.version;
                    }
                    return L;
                } else {
                    if (b === 'ask') {
                        return a + '/ask/kw' + H;
                    } else {
                        if (b === 'ask-lista' || b === 'ask-listb') {
                            return a + '/ask/list/' + app.id + '/kw' + H;
                        } else {
                            if (b === 'ask-list') {
                                return a + '/ask/list/kw' + H;
                            }
                        }
                    }
                }
            }
        }

        function G() {
            $searchList.hide();
            if (s.get().length === 0) {
                A();
                $('.search-keyword').each(function () {
                    var n = b;
                    if (b == 'newhouseIndex') {
                        n = 'newhouse';
                    }
                    if ($(this).data('type') === n) {
                        $(this).css('display', 'block');
                    }
                });
            }
        }

        function A() {
            $('.search-keyword').each(function () {
                $(this).css('display', 'none');
            });
        }

        var x = 0;
        var C = false;
        var F = {x: 0, y: 0, t: 0};
        var y = {x: 0, y: 0, t: 0};
        var j = $('.items-body');
        $('.search-list').on('touchstart', function (n) {
            $.extend(F, {
                x: n.originalEvent.touches[0].pageX,
                y: n.originalEvent.touches[0].pageY,
                t: new Date().getTime()
            });
            j.prefix({
                'transition-property': 'all',
                'transition-duration': '0s',
                'transition-timing-function': 'ease-out'
            });
            h.blur();
        }).on('touchmove', function (J) {
            J.originalEvent.preventDefault();
            $.extend(y, {
                x: J.originalEvent.touches[0].pageX,
                y: J.originalEvent.touches[0].pageY,
                t: new Date().getTime()
            });
            var n = $(this).height() - j.height();
            if (n < 0) {
                C = (typeof J.originalEvent.touches[0] === 'object');
                var H = parseFloat(j.data('number'));
                var I = H + y.y - F.y;
                if (I > 0) {
                    I = I / 3;
                } else {
                    if (I < n) {
                        I = (I - n) / 3 + n;
                    }
                }
                j.prefix({'transform': 'translate3d(0,' + I + 'px,0)'});
            }
        }).on('touchend', function (M) {
            var H = $(this).height() - j.height();
            if (C && H < 0) {
                var K = parseFloat(j.data('number'));
                var L;
                var n = 1;
                if (y.y - F.y < 0) {
                    n = -1;
                }
                var I = (y.y - F.y) / (y.t - F.t);
                var J = Math.pow(I, 2) / (2 * n) * 300;
                K += y.y - F.y + J;
                L = K;
                if (K > 0) {
                    L = 0;
                } else {
                    if (K < H) {
                        L = H;
                    }
                }
                j.prefix({'transition-duration': '.3s'});
                j.prefix({'transform': 'translate3d(0,' + L + 'px,0)'});
                K = L;
                j.data('number', K);
            }
        });
        q.tap(function (n) {
            s.remove();
            z('_history_', s.get());
            n.stopPropagation();
            n.preventDefault();
            G();
        });
        $('.option').on('tap', 'a', function (H) {
            H.stopPropagation();
            H.preventDefault();
            b = $(this).attr('biz');
            $('.type-current').find('span').text($(this).text());
            $('input.text').val('').attr('placeholder', app.placeholders[b]);
            l.hide();
            var n = s.get();
            if (n.length === 0) {
                G();
            } else {
                A();
                z('_history_', n);
                $searchList.show();
            }
            $('.option').hide();
        });

        function z(H, J) {
            $('.search-recommend').hide();
            var n = '';
            var I = false;
            if (J && J.length > 0) {
                $.each(J, function (L, M) {
                    if (H == 'sale' && M.keywordType == 'RECOMMEND') {
                        I = true;
                        return false;
                    }
                    n += v.handle(H, L, M);
                });
            }
            if (H == '_history_' && n) {
                $('.clear-record').show();
            } else {
                $('.clear-record').hide();
            }
            if (n) {
                $('.search-list .items-body').show().data('number', 0);
            } else {
                $('.search-list .items-body').hide();
            }
            if (H === 'rates' && n === '') {
                n = '<a class="items" href="javascript:;"><span class="txt">没有相关结果</span></a>';
            }
            if (!I) {
                k.html(n);
            }
            if (I) {
                var K = '您是否在找:';
                $.each(J, function (L, M) {
                    K += '<a class="keyword" href="' + app.ctx + '/sale?keyword=' + M.keyword + '">' + M.keyword + '</a>';
                });
                $('.clear-record').hide();
                $('.search-list').hide();
                $('.js-searchRecommendResult').html(K);
                $('.search-recommend').show();
                G();
            }
        }

        return {
            show: function (n) {
                h.val(n);
                w.show();
                G();
                h.focus();
            }
        };
    })();
    $('#search-entry').on('focus', function (g) {
        g.preventDefault();
        g.stopPropagation();
        c.show($(this).val());
    }).tap(function (g) {
        g.preventDefault();
        c.show($(this).val());
    });
    $('.type-current').tap(function (h) {
        h.stopPropagation();
        var g = $(this).next('.type-options');
        if (g.css('display') == 'none') {
            g.show();
        } else {
            g.hide();
        }
    });
    $(document).tap(function () {
        $('.type-options').hide();
    });

    function d(g, h, i) {
        e.find('p').text(g);
        e.fadeIn();
        if (!i && $.isFunction(h)) {
            i = h;
            tiem = 1300;
        }
        setTimeout(function () {
            e.fadeOut();
            setTimeout(function () {
                i && i();
            }, 400);
        }, h || 1300);
    }
});